package com.ruoyi.zhmk.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhmk.domain.ZhmkDoorDevice;
import com.ruoyi.zhmk.service.IZhmkDoorDeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门禁设备Controller
 * 
 * @author ruoyi
 * @date 2021-06-24
 */
@Api("门禁设备")
@RestController
@RequestMapping("/zhmk/doordevice")
public class ZhmkDoorDeviceController extends BaseController
{
    @Autowired
    private IZhmkDoorDeviceService zhmkDoorDeviceService;

    /**
     * 查询门禁设备列表
     */
    @PreAuthorize("@ss.hasPermi('zhmk:doordevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhmkDoorDevice zhmkDoorDevice)
    {
        startPage();
        List<ZhmkDoorDevice> list = zhmkDoorDeviceService.selectZhmkDoorDeviceList(zhmkDoorDevice);
        return getDataTable(list);
    }

    /**
     * 导出门禁设备列表
     */
    @PreAuthorize("@ss.hasPermi('zhmk:doordevice:export')")
    @Log(title = "门禁设备", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZhmkDoorDevice zhmkDoorDevice)
    {
        List<ZhmkDoorDevice> list = zhmkDoorDeviceService.selectZhmkDoorDeviceList(zhmkDoorDevice);
        ExcelUtil<ZhmkDoorDevice> util = new ExcelUtil<ZhmkDoorDevice>(ZhmkDoorDevice.class);
        return util.exportExcel(list, "门禁设备数据");
    }

    /**
     * 获取门禁设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhmk:doordevice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zhmkDoorDeviceService.selectZhmkDoorDeviceById(id));
    }

    /**
     * 新增门禁设备
     */
    @PreAuthorize("@ss.hasPermi('zhmk:doordevice:add')")
    @Log(title = "门禁设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhmkDoorDevice zhmkDoorDevice)
    {
        return toAjax(zhmkDoorDeviceService.insertZhmkDoorDevice(zhmkDoorDevice));
    }

    /**
     * 修改门禁设备
     */
    @PreAuthorize("@ss.hasPermi('zhmk:doordevice:edit')")
    @Log(title = "门禁设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhmkDoorDevice zhmkDoorDevice)
    {
        return toAjax(zhmkDoorDeviceService.updateZhmkDoorDevice(zhmkDoorDevice));
    }

    /**
     * 删除门禁设备
     */
    @PreAuthorize("@ss.hasPermi('zhmk:doordevice:remove')")
    @Log(title = "门禁设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zhmkDoorDeviceService.deleteZhmkDoorDeviceByIds(ids));
    }

    /**
     * 查询全部
     * @return
     */
    @ApiOperation("查询全部")
    @GetMapping("/findAll")
    public AjaxResult findAll(){
        return AjaxResult.success(zhmkDoorDeviceService.selectZhmkDoorDeviceList(new ZhmkDoorDevice()));
    }
}
